package thread;

public class demo1 {
    public static boolean isQuit =false;//标志位
    public static void main(String[] args) throws InterruptedException {
          Thread t=new Thread(()->{
              while (!isQuit){
                  System.out.println("hello,thread");
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          });
          t.start();

          //假设主线程这里还要一些逻辑需求，执行一些后，要让t线程结束
        Thread.sleep(3000);

        //修改前面设定的标志位
        isQuit=true;
        System.out.println("终止t线程");
    }
}
